package Views;

import Controllers.VareCTR;
import Models.Vare;
import java.util.ArrayList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class VareView extends javax.swing.JFrame implements ListSelectionListener
{
	private Vare chosenVare = null;
	private VareCTR controller = new VareCTR();

    public VareView()
	{
        initComponents();
		jTable1.getSelectionModel().addListSelectionListener(this);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPasswordField1 = new javax.swing.JPasswordField();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        searchTF = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        Anuller = new javax.swing.JButton();
        Rediger = new javax.swing.JButton();
        Gem = new javax.swing.JButton();
        Luk = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        Slet = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        navnTF = new javax.swing.JTextField();
        salgsprisTF = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        oprindelseslandTF = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        beskrivelseTF = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        minbeholdningTF = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        købsprisTF = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        udlejningsprisTF = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        leverandørTF = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSlider1 = new javax.swing.JSlider();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        Search = new javax.swing.JButton();
        Tilføj = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText("Western Styles - Varer");
        jLabel1.setName("jLabel1"); // NOI18N

        jPasswordField1.setName("jPasswordField1"); // NOI18N

        jTextField1.setName("jTextField1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new VareTableModel());
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        searchTF.setName("searchTF"); // NOI18N

        jLabel3.setText("Søg:");
        jLabel3.setName("jLabel3"); // NOI18N

        Anuller.setText("A-nul-lér");
        Anuller.setEnabled(false);
        Anuller.setName("Anuller"); // NOI18N
        Anuller.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AnullerActionPerformed(evt);
            }
        });

        Rediger.setText("Re-di-ger");
        Rediger.setName("Rediger"); // NOI18N
        Rediger.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RedigerActionPerformed(evt);
            }
        });

        Gem.setText("Gem");
        Gem.setEnabled(false);
        Gem.setName("Gem"); // NOI18N
        Gem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GemActionPerformed(evt);
            }
        });

        Luk.setText("Luk");
        Luk.setName("Luk"); // NOI18N
        Luk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LukActionPerformed(evt);
            }
        });

        jProgressBar1.setName("jProgressBar1"); // NOI18N

        Slet.setText("Slet");
        Slet.setName("Slet"); // NOI18N
        Slet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SletActionPerformed(evt);
            }
        });

        jLabel2.setText("Navn:");
        jLabel2.setName("jLabel2"); // NOI18N

        navnTF.setName("navnTF"); // NOI18N

        salgsprisTF.setName("salgsprisTF"); // NOI18N

        jLabel4.setText("Salgspris:");
        jLabel4.setName("jLabel4"); // NOI18N

        oprindelseslandTF.setName("oprindelseslandTF"); // NOI18N

        jLabel5.setText("Oprindelsesland:");
        jLabel5.setName("jLabel5"); // NOI18N

        beskrivelseTF.setName("beskrivelseTF"); // NOI18N

        jLabel6.setText("Beskrivelse:");
        jLabel6.setName("jLabel6"); // NOI18N

        minbeholdningTF.setName("minbeholdningTF"); // NOI18N

        jLabel7.setText("Min. Beholdning:");
        jLabel7.setName("jLabel7"); // NOI18N

        købsprisTF.setName("købsprisTF"); // NOI18N

        jLabel8.setText("Købspris:");
        jLabel8.setName("jLabel8"); // NOI18N

        udlejningsprisTF.setName("udlejningsprisTF"); // NOI18N

        jLabel9.setText("Udlejningspris:");
        jLabel9.setName("jLabel9"); // NOI18N

        leverandørTF.setName("leverandørTF"); // NOI18N

        jLabel10.setText("Leverandør:");
        jLabel10.setName("jLabel10"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jSlider1.setName("jSlider1"); // NOI18N

        jLabel11.setText("Awesomeness");
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setText("Login:");
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText("Password:");
        jLabel13.setName("jLabel13"); // NOI18N

        Search.setText("Søg");
        Search.setName("Search"); // NOI18N
        Search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchActionPerformed(evt);
            }
        });

        Tilføj.setText("Til-føj");
        Tilføj.setName("Tilføj"); // NOI18N
        Tilføj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TilføjActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel1)
                                    .add(jLabel3))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 434, Short.MAX_VALUE)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jLabel12)
                                    .add(jLabel13))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPasswordField1)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                                .add(Luk)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 188, Short.MAX_VALUE)
                                .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 273, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(63, 63, 63)
                                .add(Gem)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(Anuller))
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 709, Short.MAX_VALUE)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(4, 4, 4)
                                .add(Tilføj)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(Rediger)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(Slet))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(searchTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(Search))))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(18, 18, 18)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel6)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(beskrivelseTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel5)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(oprindelseslandTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel4)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(salgsprisTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel2)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(navnTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(18, 18, 18)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jLabel7)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(minbeholdningTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                                .add(jLabel8)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(købsprisTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(6, 6, 6)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jLabel9)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(udlejningsprisTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jLabel11)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(jSlider1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 132, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jLabel10)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(leverandørTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 709, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel12))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jPasswordField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3)
                    .add(jLabel13))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(searchTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(Search))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 195, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(Slet)
                    .add(Tilføj)
                    .add(Rediger))
                .add(4, 4, 4)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(navnTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel7)
                    .add(minbeholdningTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(salgsprisTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(købsprisTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel5)
                            .add(oprindelseslandTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel6)
                            .add(beskrivelseTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(udlejningsprisTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel9))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(leverandørTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel10))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jSlider1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel11))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(Anuller)
                        .add(Luk)
                        .add(Gem))
                    .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void RedigerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RedigerActionPerformed
		this.populateFieldsWithChosenVare();
	}//GEN-LAST:event_RedigerActionPerformed

	private void SletActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SletActionPerformed
		if (jTable1.getSelectedRowCount() > 0)
		{
			this.controller.delete(chosenVare.getId());
			this.clearFields();
			this.SearchActionPerformed(null);
		}
	}//GEN-LAST:event_SletActionPerformed

	private void LukActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LukActionPerformed
		this.dispose();
	}//GEN-LAST:event_LukActionPerformed

	private void GemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GemActionPerformed
		if(chosenVare != null)
		{
			String navn = navnTF.getText();
			String salgspris = salgsprisTF.getText();
			String oprindelsesland = oprindelseslandTF.getText();
			String beskrivelse = beskrivelseTF.getText();
			String minbeholdning = minbeholdningTF.getText();
			String købspris = købsprisTF.getText();
			String udlejningspris = udlejningsprisTF.getText();
			String leverandør = leverandørTF.getText();

			int result = 0;
			if (chosenVare.getId() == 0)
			{
				result = this.controller.insertVare(this.chosenVare, navn, Double.parseDouble(salgspris), oprindelsesland, beskrivelse, Integer.parseInt(minbeholdning), Double.parseDouble(købspris), Double.parseDouble(udlejningspris), Integer.parseInt(leverandør));
			}
			else
			{
				result = this.controller.updateVare(this.chosenVare, navn, Double.parseDouble(salgspris), oprindelsesland, beskrivelse, Integer.parseInt(minbeholdning), Double.parseDouble(købspris), Double.parseDouble(udlejningspris), Integer.parseInt(leverandør));
			}
			this.chosenVare = null;
			this.clearFields();
			this.jTable1.setModel(new VareTableModel());
		}
	}//GEN-LAST:event_GemActionPerformed

	private void AnullerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnullerActionPerformed
		this.chosenVare = null;
		this.clearFields();
		this.jTable1.setModel(new VareTableModel());
	}//GEN-LAST:event_AnullerActionPerformed

	private void SearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchActionPerformed
		String searchText = searchTF.getText();
		ArrayList<Vare> chosenVarer = this.controller.searchVareName(searchText, false);
		jTable1.setModel(new VareTableModel(chosenVarer));
	}//GEN-LAST:event_SearchActionPerformed

	private void TilføjActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TilføjActionPerformed
		chosenVare = new Vare();
		clearFields();
		enableFields();
}//GEN-LAST:event_TilføjActionPerformed

	private void populateFieldsWithChosenVare()
	{
		enableFields();
		navnTF.setText(chosenVare.getNavn());
		salgsprisTF.setText(String.valueOf(chosenVare.getSalgspris()));
		oprindelseslandTF.setText(chosenVare.getOprindelsesland());
		beskrivelseTF.setText(chosenVare.getBeskrivelse());
		minbeholdningTF.setText(String.valueOf(chosenVare.getMinbeholdning()));
		købsprisTF.setText(String.valueOf(chosenVare.getKøbspris()));
		udlejningsprisTF.setText(String.valueOf(chosenVare.getUdlejningspris()));
		leverandørTF.setText(String.valueOf(chosenVare.getLeverandør()));
	}

	private void clearFields()
	{
		disableFields();
		navnTF.setText("");
		salgsprisTF.setText("");
        oprindelseslandTF.setText("");
        beskrivelseTF.setText("");
        minbeholdningTF.setText("");
		købsprisTF.setText("");
		udlejningsprisTF.setText("");
		leverandørTF.setText("");
	}

	private void disableFields()
	{
		navnTF.setEnabled(false);
		salgsprisTF.setEnabled(false);
		oprindelseslandTF.setEnabled(false);
		beskrivelseTF.setEnabled(false);
		minbeholdningTF.setEnabled(false);
		købsprisTF.setEnabled(false);
		udlejningsprisTF.setEnabled(false);
		leverandørTF.setEnabled(false);
		Gem.setEnabled(false);
		Anuller.setEnabled(false);
	}
	
	private void enableFields()
	{
		navnTF.setEnabled(true);
		salgsprisTF.setEnabled(true);
		oprindelseslandTF.setEnabled(true);
		beskrivelseTF.setEnabled(true);
		minbeholdningTF.setEnabled(true);
		købsprisTF.setEnabled(true);
		udlejningsprisTF.setEnabled(true);
		leverandørTF.setEnabled(true);
		Gem.setEnabled(true);
		Anuller.setEnabled(true);
	}
	
	public void valueChanged(ListSelectionEvent e)
	{
		if(jTable1.getSelectedRowCount() == 1)
		{
			int chosenId = Integer.parseInt(jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString());
			chosenVare = controller.findVare(String.valueOf(chosenId), false);
		}
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Anuller;
    private javax.swing.JButton Gem;
    private javax.swing.JButton Luk;
    private javax.swing.JButton Rediger;
    private javax.swing.JButton Search;
    private javax.swing.JButton Slet;
    private javax.swing.JButton Tilføj;
    private javax.swing.JTextField beskrivelseTF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField købsprisTF;
    private javax.swing.JTextField leverandørTF;
    private javax.swing.JTextField minbeholdningTF;
    private javax.swing.JTextField navnTF;
    private javax.swing.JTextField oprindelseslandTF;
    private javax.swing.JTextField salgsprisTF;
    private javax.swing.JTextField searchTF;
    private javax.swing.JTextField udlejningsprisTF;
    // End of variables declaration//GEN-END:variables
}